package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.isolation.medical.MedicalPlaceExcel;
import com.lnking.lnkingplace.model.entity.IsolationMedicalPlace;
import com.lnking.lnkingplace.model.request.isolation.medicalPlace.MedicalPlaceAddRequest;
import com.lnking.lnkingplace.model.request.isolation.medicalPlace.MedicalPlaceSearchRequest;
import com.lnking.lnkingplace.model.request.isolation.medicalPlace.MedicalPlaceUpdateRequest;
import com.lnking.lnkingplace.service.IIsolationMedicalPlaceService;
import com.lnking.starter.export.utils.ExportUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/isolation-medical-place")
@Api(tags = "医务人员保障场所")
public class IsolationMedicalPlaceController {

    @Resource
    IIsolationMedicalPlaceService iIsolationMedicalPlaceService;

    @ApiOperation(value = "导出")
    @GetMapping("export")
    public void export(MedicalPlaceSearchRequest params, HttpServletResponse response) throws Exception {
        List<IsolationMedicalPlace> data = (List<IsolationMedicalPlace>)iIsolationMedicalPlaceService.pageList(params);
        ExportUtils.export(data, response, MedicalPlaceExcel.class);
    }

    @ApiOperation("导入")
    @PostMapping("import")
    public ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception{
        iIsolationMedicalPlaceService.importExcel(file);
        return ReturnResult.success();
    }

    @ApiOperation("查询列表")
    @GetMapping("list")
    public ReturnResult getList(MedicalPlaceSearchRequest params){
        return ReturnResult.success(iIsolationMedicalPlaceService.pageList(params));
    }

    @ApiOperation("新增")
    @PostMapping("add")
    public ReturnResult add(@Valid @RequestBody MedicalPlaceAddRequest params){
        iIsolationMedicalPlaceService.add(params);
        return ReturnResult.success();
    }

    @ApiOperation("修改")
    @PostMapping("update")
    public ReturnResult update(@Valid @RequestBody MedicalPlaceUpdateRequest params){
        iIsolationMedicalPlaceService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("查询详情")
    @GetMapping("get-details")
    public ReturnResult getDetails(String id) {
        return ReturnResult.success(iIsolationMedicalPlaceService.getById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        iIsolationMedicalPlaceService.removeById(id);
        return ReturnResult.success();
    }
}
